package cn.saltybe.analysis.crawler;

import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.request.HttpGetRequest;

import java.util.HashMap;
import java.util.Map;


public class InitGecco {
    public InitGecco(boolean block) {
        System.out.println("即将开始扫描 58同城 房产数据……");

        HttpGetRequest startRequest = new HttpGetRequest("https://www.58.com/changecity.html?fullpath=0");
        // HttpGetRequest startRequest = new HttpGetRequest("https://hf.58.com/xinfang");
        Map<String, String> map = new HashMap<>();
        map.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36 Edg/91.0.864.48");
        startRequest.setHeaders(map);
        startRequest.setCharset("utf-8");

        GeccoEngine engine = GeccoEngine.create()
                .classpath("cn.saltybe.analysis.crawler")
                .interval(30000)
                .loop(false)
                .retry(1)
                .start(startRequest);
        if (block) engine.run();
        else engine.start();
    }
}
